package com.itheima.tliasmanagent.service.impl;

import com.itheima.tliasmanagent.mapper.EmpMapper;
import com.itheima.tliasmanagent.mapper.StudentMapper;
import com.itheima.tliasmanagent.pojo.ClazzCountOption;
import com.itheima.tliasmanagent.pojo.JobOption;
import com.itheima.tliasmanagent.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;
    @Override
    public JobOption getEmpJobData() {
      List<Map<String,Object>> list= empMapper.countEmpJobData();

        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();
        return new JobOption(jobList,dataList);
    }

    @Override
    public List<Map> getEmpGenderData() {
        return  empMapper.getEmpGenderData();
    }


    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    @Override
    public ClazzCountOption getStudentCountData() {
        List<Map<String, Object>> countList = studentMapper.getStudentCount();
        if(!CollectionUtils.isEmpty(countList)){
            List<Object> clazzList = countList.stream().map(map -> {
                return map.get("cname");
            }).toList();

            List<Object> dataList = countList.stream().map(map -> {
                return map.get("scount");
            }).toList();

            return new ClazzCountOption(clazzList, dataList);
        }
        return null;
    }

    public JobOption empJobData() {
        List<Map> mapList = empMapper.getJobData();
        log.info("mapList: {}", mapList);
        //职位列表
        List<Object> jobList = mapList.stream().map(map -> {
            return map.get("pos");
        }).collect(Collectors.toList());
        //职位人数列表
        List<Object> dataList = mapList.stream().map(map -> {
            return map.get("posCount");
        }).collect(Collectors.toList());

        return new JobOption(jobList, dataList);
    }

}
